package com.ruoyi.boat.controller;

import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.ruoyi.boat.aop.AvoidDuplicate;
import com.ruoyi.common.utils.DateUtils;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.boat.domain.Statistic;
import com.ruoyi.boat.service.IStatisticService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 统计Controller
 *
 * @author ruoyi
 * @date 2023-08-13
 */
@Controller
@RequestMapping("/boat/statistic")
public class StatisticController extends BaseController {
    private String prefix = "boat/statistic";

    @Autowired
    private IStatisticService statisticService;

    @RequiresPermissions("boat:statistic:view")
    @GetMapping()
    public String statistic() {
        return prefix + "/statistic";
    }

    /**
     * 查询统计列表
     */
    @RequiresPermissions("boat:statistic:list")
    @PostMapping("/list")
    @ApiOperation("查询")
    @ResponseBody
    public TableDataInfo list(Statistic statistic) {
        startPage();
        List<Statistic> list = statisticService.selectStatisticList(statistic);
        return getDataTable(list);
    }

    /**
     * 导出统计列表
     */
    @RequiresPermissions("boat:statistic:export")
    @Log(title = "统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AvoidDuplicate
    @ResponseBody
    public AjaxResult export(Statistic statistic) {
        List<Statistic> list = statisticService.selectStatisticList(statistic);
        ExcelUtil<Statistic> util = new ExcelUtil<Statistic>(Statistic.class);
        return util.exportExcel(list, "统计数据");
    }

    /**
     * 新增统计
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存统计
     */
    @RequiresPermissions("boat:statistic:add")
    @Log(title = "统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Statistic statistic) {
        return toAjax(statisticService.insertStatistic(statistic));
    }

    /**
     * 修改统计
     */
    @RequiresPermissions("boat:statistic:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Statistic statistic = statisticService.selectStatisticById(id);
        mmap.put("statistic", statistic);
        return prefix + "/edit";
    }

    /**
     * 修改保存统计
     */
    @RequiresPermissions("boat:statistic:edit")
    @Log(title = "统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Statistic statistic) {
        return toAjax(statisticService.updateStatistic(statistic));
    }

    /**
     * 删除统计
     */
    @RequiresPermissions("boat:statistic:remove")
    @Log(title = "统计", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(statisticService.deleteStatisticByIds(ids));
    }

    /**
     * 统计
     */
    @RequiresPermissions("boat:statistic:list")
    @GetMapping("/detail")
    @ApiOperation("统计")
    @ResponseBody
    public Object byDate() {
        return statisticService.selectTodayThisWeekThisMonthStatistic();
    }
}
